<template>
	<view class="content">
		<!--标题栏-->
		<bar-title bgColor='bg-white' :isSolid="false" >
			<block slot="content">我的评价</block>
		</bar-title>
		
		<!-- 导航 -->
		<view class="navbar-box cu-bar fixed">
			<view class="cu-capsule radius">
				<view class='cu-tag '
					v-for="(item, index) in navList" :key="index"
					:class="{active:tabCurrentIndex === index}"
					@click="tabClick(index)"
				>
					{{item.text}}(1)
				</view>
			</view>
		</view>		
		
		<!-- 订单 -->
		<swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
			<swiper-item class="tab-content" v-for="(tabItem,tabIndex) in navList" :key="tabIndex">
				<scroll-view 
					class="list-scroll-content" 
					scroll-y
					@scrolltolower="loadData"
				>
					<!-- 空白页 -->
					<empty v-if="tabItem.loaded === true && tabItem.evaluateList.length === 0"></empty>
					
					<!-- 订单列表 -->
					<view class="evaluate-list">
						<block v-for="(item,index) in tabItem.evaluateList" :key="index">
							<ViewEvaluate></ViewEvaluate>
						</block>
					</view>
					 
					<uni-load-more :status="tabItem.loadingType"></uni-load-more>
					
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template> 

<script>
	import uniLoadMore from '@/components/basics/uni-load-more/uni-load-more.vue';
	import empty from "@/components/basics/empty";
	// import ViewEvaluate from "@/components/box/ViewEvaluate";

	export default {
		components: {
			uniLoadMore,
			empty,
			// ViewEvaluate
		},
		data() {
			return {
				tabCurrentIndex: 0,
				navList: [{
						state: 0,
						text: '已评价',
						loadingType: 'more',
						evaluateList: [{},{}]
					},
					{
						state: 1,
						text: '未评价',
						loadingType: 'more',
						evaluateList: []
					}
				],
			};
		},
		
		onLoad(options){
			this.tabCurrentIndex = options.state || 0;
			this.loadData()
		},
		methods: {
			//获取订单列表
			loadData(source){
				//这里是将订单挂载到tab列表下
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				let state = navItem.state;
				
				if(source === 'tabChange' && navItem.loaded === true){
					//tab切换只有第一次需要加载数据
					return;
				}
				if(navItem.loadingType === 'loading'){
					//防止重复加载
					return;
				}
				navItem.loadingType = 'loading';
				
				setTimeout(()=>{
					[1,2,3,4,5,6,7,8,9].forEach(item=>{
						navItem.evaluateList.push(item);
					})
					//loaded新字段用于表示数据加载完毕，如果为空可以显示空白页
					this.$set(navItem, 'loaded', true);
					
					//判断是否还有数据， 有改为 more， 没有改为noMore 
					navItem.loadingType = 'more';
				}, 600);	
			}, 

			//swiper 切换
			changeTab(e){
				this.tabCurrentIndex = e.target.current;
				this.loadData('tabChange');
			},
			//顶部tab点击
			tabClick(index){
				this.tabCurrentIndex = index;
			},
			
		},
	}
</script>

<style lang="scss" scoped>
	page, .content{
		background: $page-color-base;
		height: 100%;
	}
	.swiper-box{
		height: calc(100% - var(--status-bar-height) - 101rpx)
	}
	.list-scroll-content{
		height: 100%;
	}
	.evaluate-list{
		padding-top: 140upx;
	}
	.navbar-box{
		top: var(--status-bar-height);
		margin-top: 100rpx;
		padding: 20rpx 30rpx;
		box-shadow: none;
		.cu-capsule{
			overflow: hidden;
			border-radius: 10px;
			width: 100%;
		}
		.cu-tag {
			flex: 1;
			height: 100rpx;
			font-size: 15px;
			font-weight: 400;
			background-color: #fff;
			&.active {
				background-color: $base-color;
				color: #fff;
			}
		}
	}
	.uni-swiper-item{
		height: auto;
	}
	
	
	/* load-more */
	.uni-load-more {
		display: flex;
		flex-direction: row;
		height: 80upx;
		align-items: center;
		justify-content: center
	}
	
	.uni-load-more__text {
		font-size: 28upx;
		color: #999
	}
	
	.uni-load-more__img {
		height: 24px;
		width: 24px;
		margin-right: 10px
	}
	
	.uni-load-more__img>view {
		position: absolute
	}
	
	.uni-load-more__img>view view {
		width: 6px;
		height: 2px;
		border-top-left-radius: 1px;
		border-bottom-left-radius: 1px;
		background: #999;
		position: absolute;
		opacity: .2;
		transform-origin: 50%;
		animation: load 1.56s ease infinite
	}
	
	.uni-load-more__img>view view:nth-child(1) {
		transform: rotate(90deg);
		top: 2px;
		left: 9px
	}
	
	.uni-load-more__img>view view:nth-child(2) {
		transform: rotate(180deg);
		top: 11px;
		right: 0
	}
	
	.uni-load-more__img>view view:nth-child(3) {
		transform: rotate(270deg);
		bottom: 2px;
		left: 9px
	}
	
	.uni-load-more__img>view view:nth-child(4) {
		top: 11px;
		left: 0
	}
	
	.load1,
	.load2,
	.load3 {
		height: 24px;
		width: 24px
	}
	
	.load2 {
		transform: rotate(30deg)
	}
	
	.load3 {
		transform: rotate(60deg)
	}
	
	.load1 view:nth-child(1) {
		animation-delay: 0s
	}
	
	.load2 view:nth-child(1) {
		animation-delay: .13s
	}
	
	.load3 view:nth-child(1) {
		animation-delay: .26s
	}
	
	.load1 view:nth-child(2) {
		animation-delay: .39s
	}
	
	.load2 view:nth-child(2) {
		animation-delay: .52s
	}
	
	.load3 view:nth-child(2) {
		animation-delay: .65s
	}
	
	.load1 view:nth-child(3) {
		animation-delay: .78s
	}
	
	.load2 view:nth-child(3) {
		animation-delay: .91s
	}
	
	.load3 view:nth-child(3) {
		animation-delay: 1.04s
	}
	
	.load1 view:nth-child(4) {
		animation-delay: 1.17s
	}
	
	.load2 view:nth-child(4) {
		animation-delay: 1.3s
	}
	
	.load3 view:nth-child(4) {
		animation-delay: 1.43s
	}
	
	@-webkit-keyframes load {
		0% {
			opacity: 1
		}
	
		100% {
			opacity: .2
		}
	}
</style>
